//
//  BaseNavViewController.swift
//  Weobo
//
//  Created by 史亚洲 on 16/1/19.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class BaseNavViewController: UINavigationController ,UIGestureRecognizerDelegate{

     override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate=self
        
       

        // Do any additional setup after loading the view.
    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //调用super的方法
        if childViewControllers.count != 0 {
            viewController.hidesBottomBarWhenPushed=true
            
            let btn = UIButton(title: "返回", color: UIColor.darkGrayColor(), fontSize: 14, backImageName: nil,imageName: "navigationbar_back_withtext")
            btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
            viewController.navigationItem.leftBarButtonItem=UIBarButtonItem(customView: btn)

        
        }
        //这一句代码执行完毕后才能真正添加到导航控制器成为子视图
        super.pushViewController(viewController, animated: true)
    }
    @objc private func back() {
    
    popViewControllerAnimated(true)
    
    }
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        print("OK")
        return childViewControllers.count>1
    }

}
